Skip to content

fix: tighten MCPServer tool result typing#2881

Closed
sarvesh1327 wants to merge 4 commits into
modelcontextprotocol:mainfrom
sarvesh1327:fix/mcpserver-call-tool-result-type
Closed

fix: tighten MCPServer tool result typing#2881
sarvesh1327 wants to merge 4 commits into
modelcontextprotocol:mainfrom
sarvesh1327:fix/mcpserver-call-tool-result-type

Conversation

@sarvesh1327

Copy link
Copy Markdown

Summary

  • Remove the unreachable raw-dict branch in MCPServer._handle_call_tool
  • Update MCPServer.call_tool to describe the actual converted result shapes
  • Add coverage for unstructured dict conversion staying as text content

Fixes #2695.

Test Plan

  • uv run --frozen pytest tests/server/mcpserver/test_func_metadata.py -q
  • uv run --frozen ruff check src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_func_metadata.py
  • uv run --frozen pyright src/mcp/server/mcpserver/server.py tests/server/mcpserver/test_func_metadata.py

Notes

  • Scope intentionally small.

Comment thread src/mcp/server/mcpserver/server.py Outdated
Comment on lines +391 to +393
async def call_tool(
self, name: str, arguments: dict[str, Any], context: Context[LifespanResultT, Any] | None = None
) -> Sequence[ContentBlock] | dict[str, Any]:
) -> CallToolResult | Sequence[ContentBlock] | tuple[Sequence[ContentBlock], dict[str, Any]]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason I didn't do this is because I think we should only return CallToolResult from here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea probably a good idea

@Kludex Kludex closed this Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dead code path in MCPServer._handle_call_tool and incorrect call_tool return type

3 participants